<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\Database\Model\SoftDeletes;

/**
 * @property int $id 
 * @property int $type 
 * @property string $title 
 * @property string $image 
 * @property string $link 
 * @property int $status 
 * @property int $sort 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 * @property int $deleted_at 
 */
class Advertising extends Model
{
    public $dateFormat = 'U';

    use SoftDeletes;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'advertising';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['id', 'type', 'title', 'jump_type', 'link', 'start_time', 'end_time', 'business_name', 'contacts', 'phone', 'industry_id', 'industry_id', 'location_id', 'status', 'image'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'int', 'type' => 'integer', 'status' => 'boolean', 'jump_type' => 'integer', 'sort' => 'integer', 'created_at' => 'integer', 'updated_at' => 'datetime', 'deleted_at' => 'integer'];

    /**
     * 定义状态字段
     * @var array 
     */
    protected $appends = [ 'status_text', 'jump_text', 'type_text'];

    /**
     * 创建时间
     * @return false|string
     */
    public function getCreatedAtAttribute($value)
    {
        return date('Y-m-d', (int)$value);
    }


    /**
     * 状态名称
     * @return mixed|string
     */
    public function getStatusTextAttribute()
    {
        $status_text = [
          0 => '禁用',
          1 => '正常'
        ];
        return $status_text[$this->status]??"无";
    }

    /**
     * 跳转名称
     * @return mixed|string
     */
    public function getJumpTextAttribute()
    {
        $jump_text = [
          1 => '店铺',
          2 => '优惠券',
          3 => '积分商城',
          4 => '活动',
          5 => 'H5',
          6 => '无'
        ];
        return $jump_text[$this->jump_type]??'无';
    }

    /**
     * 广告类型名称
     * @return mixed|string
     */
    public function getTypeTextAttribute()
    {
        $type_text = [
            1 => 'APP首页',
            2 => '积分商城',
            3 => 'APP启动',
            4 => 'APP开屏广告',
            5 => '活动闪屏',
            6 => '商城支付',
            7 => '线下支付',
            8 => '线下分享',
        ];
        return $type_text[$this->type]??"无";
    }
}